package com.qn;

import com.qn.pipeline.context.InstanceBuildContext;
import com.qn.pipeline.PipelineExecutor;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.HashMap;
import java.util.Map;

@SpringBootTest
@Slf4j
class Pipeline {

    @Resource
    private PipelineExecutor pipelineExecutor;

    @Test
    public void test_AuthLink() throws ParseException {
        Map<String, Object> formInput = new HashMap<>();
        formInput.put("instanceName", "123456");
        InstanceBuildContext data = new InstanceBuildContext();
        data.setFormInput(formInput);
        // 同步
        //boolean success = pipelineExecutor.acceptSync(data);
        //
        //// 创建模型实例成功
        //if (success) {
        //    log.info("创建模型实例成功");
        //} else {
        //
        //    log.error("创建模式实例失败：{}", data.getErrorMsg());
        //}

        // 异步
        pipelineExecutor.acceptAsync(data, (x, y) -> {
            if (y) {
                log.info("创建模型实例成功");
            } else {

                log.error("创建模式实例失败：{}", data.getErrorMsg());
            }
        });

        //log.info(JSON.toJSONString(data));
    }
}
